package com.xjc.business.controller.schadmin;

import com.xjc.business.entity.po.schadmin.TimePeriodPo;
import com.xjc.business.entity.vo.schadmin.TimePeriodVo;
import com.xjc.business.service.TimePeriodsService;
import com.xjc.system.constants.MyConstants;
import com.xjc.system.exception.MyException;
import com.xjc.system.result.Result;
import com.xjc.system.result.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 徐锦程
 * 时间:2025-01-29 8:07
 */
@RestController
@RequestMapping("/sch_admin/time")
public class TimePeriodController {

    @Autowired
    TimePeriodsService timePeriodsService;

    /**
     * 获取时间段
     * @param schoolId 学校id
     * @return 数据
     */
    @GetMapping("/list/{schoolId}")
    public Result<List<TimePeriodVo>> getTimePeriodList(@PathVariable(value = "schoolId",required = false) Integer schoolId) {
        if (schoolId == null) {
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }
        return timePeriodsService.getTimePeriodList(schoolId);
    }

    /**
     * 添加时间段
     * @param timePeriodPo 时间段信息
     * @return 反馈
     */
    @PostMapping("/add")
    public Result<String> addTimePeriod(@RequestBody(required = false) TimePeriodPo timePeriodPo) {
        if (timePeriodPo == null || timePeriodPo.getSchId() == null) {
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }
        return timePeriodsService.addTimePeriod(timePeriodPo);
    }

    /**
     * 删除时间段
     * @param id 时间段id
     * @return 反馈
     */
    @DeleteMapping("/delete/{id}")
    public Result<String> deleteTimePeriod(@PathVariable(value = "id",required = false) Integer id){
        if (id == null) {
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }

        timePeriodsService.removeById(id);

        return Result.okWithData("删除成功");
    }
}
